<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-row>
      <el-form-item label="稽核清单名称" prop="auditListName">
        <el-select v-model="queryParams.auditListName" filterable allow-create placeholder="请选择或输入检查项类别"
                        clearable :style="{width: '90%'}">  
                <el-option v-for="(item, index) in auditListNameOptions" :key="index" :label="item"
                          :value="item" ></el-option>
              </el-select>
      </el-form-item>
      <el-form-item label="专案名称" prop="projectName">
        <el-select v-model="queryParams.projectName" filterable allow-create placeholder="请选择或输入检查项类别"
                        clearable :style="{width: '90%'}">  
                <el-option v-for="(item, index) in projectNameOptions" :key="index" :label="item"
                          :value="item" ></el-option>
              </el-select>
      </el-form-item>
      </el-row>
      <el-form-item label="工号" prop="auditNum">
        <el-input
          v-model="queryParams.auditNum"
          placeholder="请输入工号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="稽核日期" prop="auditTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.auditTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择稽核日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['project:records:export']"
        >导出列表</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="auditId" >
            <template scope="scope">
              <span>{{scope.$index + 1}}</span>
            </template>
      </el-table-column>
      <el-table-column label="稽核清单名称" align="center" prop="auditListName" />
      <el-table-column label="稽核清单标志" align="center" prop="auditListFlag" />
      <el-table-column label="专案名称" align="center" prop="projectName" />
      <el-table-column label="检查项" align="center" prop="checkItemNum" />
      <el-table-column label="稽核人" align="center" prop="auditName" />
      <el-table-column label="稽核日期" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click=" handleUpdate(scope.row)"
            v-hasPermi="['project:records:export']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:records:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="totalopen" width="900px" append-to-body>
      <el-form :model="tbform" ref="tbform" :rules="rules" :inline="true" v-show="showSearch" label-width="160px">
        <el-form-item label="专案名称" prop="projectName">
          <el-input v-model="tbform.projectName" placeholder="请输入专案名称" readonly />
        </el-form-item>
        <el-form-item label="稽核日期" prop="auditTime">
          <el-date-picker clearable size="small"
                          v-model="tbform.auditTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择稽核日期"
                          style="width: 205px;"
                          readonly>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="稽核人" prop="auditName">
          <el-input v-model="tbform.auditName" placeholder="请输入稽核人" readonly />
        </el-form-item>
        <el-form-item label="稽核人工号" prop="auditNum">
          <el-input v-model="tbform.auditNum" placeholder="请输入稽核人工号" readonly />
        </el-form-item>
        <el-form-item label="电脑名称" prop="computerName" :style="{ display: avisibleLine }">
          <el-input v-model="tbform.computerName"  placeholder="请输入电脑名称" readonly />
        </el-form-item>
        <el-form-item label="电脑IP地址" prop="computerIpAddress" :style="{ display: bvisibleLine }" >
          <el-input v-model="tbform.computerIpAddress" placeholder="请输入电脑IP地址" readonly />
        </el-form-item>
        <el-form-item label="电脑等级" prop="computerLever" :style="{ display: cvisibleLine }" >
          <el-input v-model="tbform.computerLever" placeholder="请输入电脑等级" readonly />
        </el-form-item>
        <el-form-item label="使用人姓名" prop="userName" :style="{ display: dvisibleLine }" >
          <el-input v-model="tbform.userName" placeholder="请输入使用人姓名" readonly />
        </el-form-item>
        <el-form-item label="使用人工号" prop="userEmployeeId" :style="{ display: evisibleLine }" >
          <el-input v-model="tbform.userEmployeeId" placeholder="请输入使用人工号" readonly />
        </el-form-item>
        <el-form-item label="使用人部门" prop="userDepartment" :style="{ display: fvisibleLine }" >
          <el-input v-model="tbform.userDepartment" placeholder="请输入使用人部门" readonly />
        </el-form-item>
        <el-form-item label="IPADSN" prop="ipadsn" :style="{ display: gvisibleLine }" >
          <el-input v-model="tbform.ipadsn" placeholder="请输入IPADSN" readonly />
        </el-form-item>
        <el-form-item label="IPAD IP地址" prop="ipadIpAddress" :style="{ display: hvisibleLine }" >
          <el-input v-model="tbform.ipadIpAddress" placeholder="请输入IPADIP地址" readonly />
        </el-form-item>
        <el-form-item label="iMessage账号" prop="imessageAccount" :style="{ display: ivisibleLine }" >
          <el-input v-model="tbform.imessageAccount" placeholder="请输入iMessage账号" readonly />
        </el-form-item>
        <el-form-item label="FTP账号" prop="ftpAccount" :style="{ display: jvisibleLine }" >
          <el-input v-model="tbform.ftpAccount" placeholder="请输入FTP账号" readonly />
        </el-form-item>
        <el-form-item label="FTP使用人" prop="ftpUser" :style="{ display: kvisibleLine }" >
          <el-input v-model="tbform.ftpUser" placeholder="请输入FTP使用人" readonly />
        </el-form-item>
        <el-form-item label="邮箱地址" prop="eAddress" :style="{ display: lvisibleLine }" >
          <el-input v-model="tbform.eAddress" placeholder="请输入邮箱地址" readonly />
        </el-form-item>
        <el-form-item label="邮箱使用人" prop="eUser" :style="{ display: mvisibleLine }" >
          <el-input v-model="tbform.eUser" placeholder="请输入邮箱使用人" readonly />
        </el-form-item>
        <el-form-item label="设备名称" prop="devicename" :style="{ display: nvisibleLine }" >
          <el-input v-model="tbform.devicename" placeholder="请输入设备名称" readonly />
        </el-form-item>
        <el-form-item label="VLAN号" prop="vlanNum" :style="{ display: ovisibleLine }" >
          <el-input v-model="tbform.vlanNum" placeholder="请输入VLAN号" readonly />
        </el-form-item>
        <el-form-item label="稽核区域" prop="auditArea" :style="{ display: pvisibleLine }" >
          <el-input v-model="tbform.auditArea" placeholder="请输入稽核区域" readonly />
        </el-form-item>
        <el-form-item label="功能间" prop="functionalArea" :style="{ display: qvisibleLine }" >
          <el-input v-model="tbform.functionalArea" placeholder="请输入功能间" readonly />
        </el-form-item>
        <el-form-item label="供应商" prop="supplier" :style="{ display: rvisibleLine }" >
          <el-input v-model="tbform.supplier" placeholder="请输入供应商" readonly />
        </el-form-item>
        <el-form-item label="审核人" prop="verifier" :style="{ display: svisibleLine }" >
          <el-input v-model="tbform.verifier" placeholder="请输入审核人" readonly />
        </el-form-item>
        <el-form-item label="审核人工号" prop="verifierId" :style="{ display: tvisibleLine }" >
          <el-input v-model="tbform.verifierId" placeholder="请输入审核人工号" readonly />
        </el-form-item>
        <el-form-item label="稽核方式" prop="auditMode" :style="{ display: uvisibleLine }" >
          <el-input v-model="tbform.auditMode" placeholder="请输入稽核方式" readonly />
        </el-form-item>
        
      </el-form>

      <el-divider content-position="center">检查项</el-divider>
      <el-table
      :data="auditListAlciList"
      size="medium"
      ref="auditHeadList"
    >
      <el-table-column label="序号" prop="auditId" align="center" width="80" >
            <template scope="scope">
              <span>{{scope.$index + 1}}</span>
            </template>
          </el-table-column>
      <el-table-column label="大类" prop="mainClass" align="center" show-overflow-tooltip width="120" />
      <el-table-column label="检查项类别" prop="checkItemCategory" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="检查内容" prop="reviewContent" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="是否" prop="whether" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="稽核描述" prop="auditDescribed" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="异常处理部门" prop="exceptionHdpt" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="处理DRI姓名" prop="processDriName" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="处理DRI工号" prop="processDriId" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="完成时间" prop="completionTime" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="解决进度" prop="progress" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="状态" prop="alciState" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="是否为BUD拟定" prop="budWrite" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="是否签署ARPA协议" prop="signArpaAgreement" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="上传清单" prop="uploadListing" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="是否脱敏" prop="whetherDesensitization" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="是否最小化给予" prop="minimizeGiving" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="图档内容" prop="imageFileContent" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="传图目的" prop="uploadFigure" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="有无违规" prop="anyViolation" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="违规项目" prop="anIllegalProject" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="处理办法" prop="approach" show-overflow-tooltip align="center" width="120" />
      <el-table-column label="备注" prop="remark" show-overflow-tooltip align="center" width="120" />
    </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onceExport" >导 出</el-button>
        <el-button @click="cancel" >取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecords, getRecords, delRecords, addRecords, updateRecords, exportRecords,getRecordstory,recordsOptions } from "@/api/project/records";
import ExportJsonExcel from "js-export-excel"

export default {
  name: "Records",
  data() {
    return {
      auditHeadList: [],
      avisibleLine: "",
      bvisibleLine: "",
      cvisibleLine: "",
      dvisibleLine: "",
      evisibleLine: "",
      fvisibleLine: "",
      gvisibleLine: "",
      hvisibleLine: "",
      ivisibleLine: "",
      jvisibleLine: "",
      kvisibleLine: "",
      lvisibleLine: "",
      mvisibleLine: "",
      nvisibleLine: "",
      ovisibleLine: "",
      pvisibleLine: "",
      qvisibleLine: "",
      rvisibleLine: "",
      svisibleLine: "",
      tvisibleLine: "",
      uvisibleLine: "",
      totalopen: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 稽核记录表格数据
      recordsList: [],
      // 弹出层标题
      title: "",
      tbform: {},
      auditListAlciList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        audId: null,
        auditNum: null,
        auditListName: null,
        projectName: null,
        checkItemNum: null,
        auditName: null,
        auditTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
       
      },
      auditListNameOptions: [],
      projectNameOptions: [],
      auditList: [],
      propertList: []
    };
  },
  created() {
    this.getList();
    this.getauditListNameList();
    this.getprojectNameList();
  },
  methods: {
    /** 查询稽核记录列表 */
    getList() {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        this.recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        audId: null,
        auditNum: null,
        auditListName: null,
        projectName: null,
        checkItemNum: null,
        auditName: null,
        auditTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.audId)
      this.single = selection.length!==1
      this.multiple = !selection.length                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    },
     //获取大类下拉框
    getauditListNameList() {
      this.loading = true;
      recordsOptions().then(response => { 
        for(var i = 0;i<response.length;i ++){
          this.auditListNameOptions.push(response[i].auditListName);
        }
        for (var i = 0; i < this.auditListNameOptions.length;i ++) {
            for (let j = i + 1; j < this.auditListNameOptions.length;j ++) {
                if (this.auditListNameOptions[i] == this.auditListNameOptions[j]) {
                    this.auditListNameOptions.splice(j, 1);
                    j--;
                }
            }
        }
        this.loading = false;
      });
    },
    //获取检查项类别下拉框
    getprojectNameList() {
      this.loading = true;
      recordsOptions().then(response => {
        for(var i = 0;i<response.length;i ++){
          this.projectNameOptions.push(response[i].projectName);
        }
        for (var i = 0; i < this.projectNameOptions.length;i ++) {
            for (let j = i + 1; j < this.projectNameOptions.length;j ++) {
                if (this.projectNameOptions[i] == this.projectNameOptions[j]) {
                    this.projectNameOptions.splice(j, 1);
                    j--;
                }
            }
        }
        this.loading = false;
      });
    },
   
    /** 查看按钮操作 */
    handleUpdate(row) {
      
      this.reset();
      this.auditList = []
      this.propertList = []
      this.auditListAlciList = []
      const auditListFlag = row.auditListFlag || this.ids
      getRecordstory(auditListFlag).then(response =>{
        if(response.data[0].computerName == '0'){
          this.avisibleLine = "none"
        }else{
          this.avisibleLine = ''
        }
        if(response.data[0].computerIpAddress == '0'){
          this.bvisibleLine = "none"
        }else{
          this.bvisibleLine = ''
        }
        if(response.data[0].computerLever == '0'){
          this.cvisibleLine = "none"
        }else{
          this.cvisibleLine = ''
        }
        if(response.data[0].userName == '0'){
          this.dvisibleLine = "none"
        }else{
          this.dvisibleLine = ''
        }
        if(response.data[0].userEmployeeId == '0'){
          this.evisibleLine = "none"
        }else{
          this.evisibleLine = ''
        }
        if(response.data[0].userDepartment == '0'){
          this.fvisibleLine = "none"
        }else{
          this.fvisibleLine = ''
        }
        if(response.data[0].ipadsn == '0'){
          this.gvisibleLine = "none"
        }else{
          this.gvisibleLine = ''
        }
        if(response.data[0].ipadIpAddress == '0'){
          this.hvisibleLine = "none"
        }else{
          this.hvisibleLine = ''
        }
        if(response.data[0].imessageAccount == '0'){
          this.ivisibleLine = "none"
        }else{
          this.ivisibleLine = ''
        }
        if(response.data[0].ftpAccount == '0'){
          this.jvisibleLine = "none"
        }else{
          this.jvisibleLine = ''
        }
        if(response.data[0].ftpUser == '0'){
          this.kvisibleLine = "none"
        }else{
          this.kvisibleLine = ''
        }
        if(response.data[0].eAddress == '0'){
          this.lvisibleLine = "none"
        }else{
          this.lvisibleLine = ''
        }
        if(response.data[0].eUser == '0'){
          this.mvisibleLine = "none"
        }else{
          this.mvisibleLine = ''
        }
        if(response.data[0].devicename == '0'){
          this.nvisibleLine = "none"
        }else{
          this.nvisibleLine = ''
        }
        if(response.data[0].vlanNum == '0'){
          this.ovisibleLine = "none"
        }else{
          this.ovisibleLine = ''
        }
        if(response.data[0].auditArea == '0'){
          this.pvisibleLine = "none"
        }else{
          this.pvisibleLine = ''
        }
        if(response.data[0].functionalArea == '0'){
          this.qvisibleLine = "none"
        }else{
          this.qvisibleLine = ''
        }
        if(response.data[0].supplier == '0'){
          this.rvisibleLine = "none"
        }else{
          this.rvisibleLine = ''
        }
        if(response.data[0].verifier == '0'){
          this.svisibleLine = "none"
        }else{
          this.svisibleLine = ''
        }
        if(response.data[0].verifierId == '0'){
          this.tvisibleLine = "none"
        }else{
          this.tvisibleLine = ''
        }
        if(response.data[0].auditMode == '0'){
          this.uvisibleLine = "none"
        }else{
          this.uvisibleLine = ''
        }
      });

      const audId = row.audId || this.ids
      getRecords(audId).then(response => {
        this.tbform = response.data;
        this.auditListAlciList = response.data.auditListAlciList
        this.totalopen = true;
        this.title = "查看稽核记录";
      });
    },
     getJs2ExcelOptions(data, fileName="导出数据", headers) {
           let sData = {
           sheetData: data
           }
           if (headers && headers.length > 0) {
          sData.sheetData.unshift(headers)
           }
           // sData.sheetData.push(data)
           let options = {
           fileName,
           datas: [sData]
           }
           return options
          },
    /** 导出按钮 */
    onceExport(){
      let auditListAlciListy = this.auditListAlciList
      for(var j = 0;j<this.$refs.tbform.$data.fields.length;j ++){
          this.auditList.push(this.$refs.tbform.$data.fields[j].label)
          this.propertList.push(this.$refs.tbform.$data.fields[j].prop)
      }
      auditListAlciListy.push(this.tbform)

      for(var i = 0;i<this.$refs.auditHeadList.$children.length;i ++){
        if(this.$refs.auditHeadList.$children[i].label == undefined || this.$refs.auditHeadList.$children[i].label == '序号'){
           
        }else{
          this.auditList.push(this.$refs.auditHeadList.$children[i].label)
          this.propertList.push(this.$refs.auditHeadList.$children[i]._props.prop)
        }
      }
     
      let auditManList = []
      auditListAlciListy.forEach((el,i) =>{
      auditManList.unshift(this.propertList.map(e =>{
          return auditListAlciListy[i][e]
          }))
      })
      let options = this.getJs2ExcelOptions(auditManList,"稽核记录详情",this.auditList)
      let toExcel = new ExportJsonExcel(options)
      toExcel.saveExcel()
      this.totalopen = false;
    },
    //取消按钮
    cancel(){
      this.totalopen = false
    
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const audIds = row.audId || this.ids;
      this.$modal.confirm('是否确认删除数据项？').then(function() {
        return delRecords(audIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出列表按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有稽核记录数据项？').then(() => {
        this.exportLoading = true;
        return exportRecords(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
